public class NumArray {

    int[] nums;
    int[] dp;
    public NumArray(int[] nums) {
        this.nums = nums;
        dp = new int[nums.length];
        if (nums.length != 0) dp[0] = nums[0];
        for (int i = 1; i < nums.length; i++) {
            dp[i] = dp[i - 1] + nums[i];
        }
    }

    public int sumRange(int left, int right) {
        return dp[right] - dp[left] + nums[left];
    }
}
